//
//  FillDetailDataTableViewCell.h
//  CommunityNannyO2O
//
//  Created by apple on 15/8/13.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "FillDetailDataTableViewCell.h"
#import "APIAdress.h"
#import "MJExtension.h"
#import "UIViewController+Create.h"
#import "CustomTextField.h"
#import "AppConfig.h"
#import "FillDetailDataTableViewCell.h"
#import "QXNetWorkTool.h"
#import "UserDataSingleton.h"
#import "MBProgressHUD+YC.h"
#import "GTMBase64.h"
#import "CommFunc.h"

@interface FillDetailDataTableViewCell()<QXNetWorkToolDelegate>


@property (weak, nonatomic) IBOutlet UIImageView *head;
@property (weak, nonatomic) IBOutlet UIButton *headPhotoButton;

@property (weak, nonatomic) IBOutlet CustomTextField  *nickName;

@property (weak, nonatomic) IBOutlet CustomTextField  *mail;

@property (weak, nonatomic) IBOutlet CustomTextField  *RealName;

@property (weak, nonatomic) IBOutlet CustomTextField  *idNumber;

@property (weak, nonatomic) IBOutlet UIButton *finish;


@end

@implementation FillDetailDataTableViewCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"FillDetailDataTableViewCell";
    FillDetailDataTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        
        cell = [[[NSBundle mainBundle] loadNibNamed:ID owner:nil options:nil]firstObject];
        
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    
    return cell;
}

-(void)awakeFromNib
{
    //头像
    [self.head.layer setCornerRadius:self.head.frame.size.width / 2];
    self.head.clipsToBounds = YES;
    self.head.contentMode = UIViewContentModeScaleAspectFill;
    
    
    //叉号，一次性删除输入框中的内容
    [self.nickName setClearButtonMode:UITextFieldViewModeWhileEditing];
    [self.mail setClearButtonMode:UITextFieldViewModeWhileEditing];
    [self.RealName setClearButtonMode:UITextFieldViewModeWhileEditing];
    [self.idNumber setClearButtonMode:UITextFieldViewModeWhileEditing];
    
    //数字键盘
    self.idNumber.keyboardType = UIKeyboardTypeNumberPad;
    
    //编辑时清空
    self.nickName.clearsOnBeginEditing = YES;
    self.mail.clearsOnBeginEditing = YES;
    self.RealName.clearsOnBeginEditing = YES;
    self.idNumber.clearsOnBeginEditing = YES;
    
    //placeholder字体、颜色
    UIFont *font = [UIFont fontWithName:@"Hiragino Sans GB" size:15];
    UIColor *color = UIColorRGBA(187, 187, 187, 1);

    [self.nickName setFont:font Color:color];
    [self.mail setFont:font Color:color];
    [self.RealName setFont:font Color:color];
    [self.idNumber setFont:font Color:color];
    
    
    self.finish.layer.cornerRadius = 5;
    self.finish.layer.masksToBounds = YES;
    [self.finish.layer setBorderWidth:1.0]; //边框宽度
    [self.finish.layer setBorderColor:UIColorRGBA(19, 208, 202, 1).CGColor];//边框颜色
    [self.finish addTarget:self action:@selector(finishSender:) forControlEvents:UIControlEventTouchUpInside];
    
    //手势
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    
    [self addGestureRecognizer:tapGestureRecognizer];

    UIView *bigContainView = [self viewWithTag: 999];
    UITapGestureRecognizer *tapGestureRecognizer0 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    [bigContainView addGestureRecognizer:tapGestureRecognizer0];
    
    //子view
    UIView *containView1 = [bigContainView viewWithTag: 1];
    
    UITapGestureRecognizer *tapGestureRecognizer1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    [containView1 addGestureRecognizer:tapGestureRecognizer1];
    
    //子view
    UIView *containView2 = [bigContainView viewWithTag: 2];
    
    UITapGestureRecognizer *tapGestureRecognizer2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    [containView2 addGestureRecognizer:tapGestureRecognizer2];
    
    //
    UIView *containView3 = [bigContainView viewWithTag: 3];
    
    UITapGestureRecognizer *tapGestureRecognizer3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    [containView3 addGestureRecognizer:tapGestureRecognizer3];
    
    UIView *containView4 = [bigContainView viewWithTag: 4];
    
    UITapGestureRecognizer *tapGestureRecognizer4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    [containView4 addGestureRecognizer:tapGestureRecognizer4];
}

-(void)setHeadPhoto:(UIImage *)image
{
    [self.head setImage:image];
}

-(void)tap
{
    [self.nickName resignFirstResponder];
    [self.mail resignFirstResponder];
    [self.RealName resignFirstResponder];
    [self.idNumber resignFirstResponder];
}

- (void)GetFailResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUD];
    
    if (Response == nil)
        return;
    
    NSString *message = Response;
    
    switch (tag)
    {
        case 1:
            [MBProgressHUD showError:message];
            break;
    }
}

- (void)GetSuccessMessage:(id)message andTag:(int)tag
{
    [MBProgressHUD hideHUD];
    
    NSString *mes = message;
    
    switch (tag)
    {
        case 1:
            [MBProgressHUD showSuccess:mes];
            
            if ([self.delegate respondsToSelector:@selector(finish)]) {
                
                [self.delegate finish];
            }
            
            break;
    }
}


-(void)GetSuccessResponse:(id)Response andTag:(int)tag
{
    switch (tag)
    {
        case 1:
        {
            if (Response == nil)
            {
                return;
            }
        }
    }
}

- (void)finishSender:(id)sender
{
    [MBProgressHUD showMessage:@"正在加载"];
    
    QXNetWorkTool *QXnetWorkTool = [[QXNetWorkTool alloc]init];
    
    QXnetWorkTool.QXNetWorkDelegate = self;
    
    
    [QXnetWorkTool GetDataFromServerWithPostMethodandInterfaceName:FillDetailInterface andParameter:@[
                      @{@"user_id":[UserDataSingleton shareInstance].user_id,
                        @"real_name":self.RealName.text,
                        @"nickname":self.nickName.text,
                        @"eamil":self.mail.text,
                        @"id_card":self.idNumber.text,
                        @"province":@"",
                        @"city":@"",
                        @"phone":@"",
                        @"nationality":@"",
                        @"sex":@"",
                        @"birthday":@"",
                        @"people":@"",
                        @"head_img":[CommFunc getImageBase64String:self.head.image]}] tag:1];
}

- (IBAction)LoadUpHeadphoto:(id)sender{
    
    if ([self.delegate respondsToSelector:@selector(loadUpHeadphoto)]) {
        
        [self.delegate loadUpHeadphoto];
    }
}

@end




